<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>查看未还</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./static/layui/css/layui.css"  media="all">
    <script src="./static/layui/layui.js" charset="utf-8"></script>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>用户记录id</th>
            <th>用户id</th>
            <th>用户名</th>
            <th>图书id</th>
            <th>图书名称</th>
            <th>借书日期</th>
            <th>书籍状态</th>
            <th colspan="2">通知归还</th>
        </tr>
        </thead>
        <tbody id="table">

        </tbody>
    </table>
</div>
</body>
</html>
<script>
    $(function () {
        //发送ajax请求
        $.ajax({
            url:"./book/nowBrowList.do",//请求地址
            type:"post",//请求方式
            data:{},
            dataType:"json",//返回的数据类型：对象是json，字符串和数组：text
            success:function (data) {//响应成功需要执行的函数
                var html="";
                for(var i=0;i<data.length;i++){
                    html+="<tr>"+
                        "<td>"+data[i].browRecoredId+"</td>"+
                        "<td>"+data[i].userId+"</td>"+
                        "<td>"+data[i].user.username+"</td>"+
                        "<td>"+data[i].bookId+"</td>"+
                        "<td>"+data[i].book.bookName+"</td>"+
                        "<td>"+data[i].browDate+"</td>"+
                        "<td>"+data[i].bookState+"</td>"+
                        "<td><button type='button' onclick='informReturn(this)'>通知归还</td>"+
                        "</tr>"
                }
                //把拼接成功地html变量信息显示的id=tb的标签上<input id='dId' type='hidden' value='"+data.list[i].dept.dId+"'>
                $("#table").html(html)
            },
            error:function (data) {
                //响应失败需要做的事情
                alert("nowList页面的ajax请求失败");
            }
        })
    });

    function informReturn(obj) {
        var browRecoredId=$(obj).parent().parent().find("td").eq(0).text();
        var userId=$(obj).parent().parent().find("td").eq(1).text();
        var bookId=$(obj).parent().parent().find("td").eq(3).text();
        $.ajax({
            url:"./book/informReturn.do",
            type:"post",
            data:{
                browRecoredId:browRecoredId,
                userId:userId,
                bookId:bookId
            },
            dataType:"json",
            success:function (data) {
                alert("已通知");
                window.location.href="./noRturnBrowList.html";
            },
            error:function (data) {
                alert("ajax请求失败");
            }
        })
    };
</script>

